<?php

//decode by 012wz.com QQ:800083075
if (!defined('IN_IA')) {
	die('Access Denied');
}
global $_W, $_GPC;
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$openid = m('user')->getOpenid();
$uniacid = $_W['uniacid'];
$credit = intval(m('member')->getCredit($openid, 'credit1'));
$gold_card = intval(m('member')->getCredit($openid, 'gold_card'));
if ($_W['isajax']) {
	if ($operation == 'display') {
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		$condition = ' and log.openid=:openid and log.uniacid = :uniacid';
		$params = array(':uniacid' => $_W['uniacid'], ':openid' => $openid);
		$sql = 'SELECT COUNT(*) FROM ' . tablename('ewei_shop_goldshop_log') . " log where 1 {$condition}";
		$total = pdo_fetchcolumn($sql, $params);
		$list = array();
		if (!empty($total)) {
			$sql = 'SELECT log.id,log.goodsid,g.title,g.thumb,g.credit,g.type,g.money,log.createtime,log.gold_card FROM ' . tablename('ewei_shop_goldshop_log') . ' log ' . ' left join ' . tablename('ewei_shop_goldshop_goods') . ' g on log.goodsid = g.id ' . ' where 1 ' . $condition . ' ORDER BY log.createtime DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
			$list = pdo_fetchall($sql, $params);
			$list = set_medias($list, 'thumb');
                        foreach($list as $k=>$v){
                          $list[$k]['createtime'] = date('Y-m-d H:i:s', $v['createtime']);  
                        }
			foreach ($list as $key=>$row) {
                                if($row['gold_card']==0){
                                   unset($list[$key]); 
                                }
				if ($row['credit'] > 0 & $row['money'] > 0) {
					$row['acttype'] = 0;
				} else {
					if ($row['credit'] > 0) {
						$row['acttype'] = 1;
					} else {
						if ($goods['money'] > 0) {
							$row['acttype'] = 2;
						}
					}
				}
				$row['createtime'] = date('Y-m-d H:i:s', $row['createtime']);
			}
			unset($row);
		}
		show_json(1, array('total' => $total, 'list' => $list, 'pagesize' => $psize));
	}
}
$_W['shopshare'] = array('title' => $this->set['share_title'], 'imgUrl' => tomedia($this->set['share_icon']), 'link' => $this->createPluginMobileUrl('goldshop'), 'desc' => $this->set['share_desc']);
$com = p('commission');
if ($com) {
	$cset = $com->getSet();
	if (!empty($cset)) {
		if ($member['isagent'] == 1 && $member['status'] == 1) {
			$_W['shopshare']['link'] = $this->createPluginMobileUrl('goldshop', array('mid' => $member['id']));
			if (empty($cset['become_reg']) && (empty($member['realname']) || empty($member['mobile']))) {
				$trigger = true;
			}
		} else {
			if (!empty($_GPC['mid'])) {
				$_W['shopshare']['link'] = $this->createPluginMobileUrl('goldshop/detail', array('mid' => $_GPC['mid']));
			}
		}
	}
}
include $this->template('creditlog');